<template>
  <div>
    <span>系统开关</span>
  <el-switch
      v-model="value"
      class="ml-2"
      style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
      @change="changeSystemStatus"
  />
  </div>
</template>

<script>
import API from '@/api/manage'
export default {
  data(){
    return{
      value:true
    }
  },
  mounted() {
    this.querySystem()

  },
  methods:{
    changeSystemStatus(value){
      let token = localStorage.getItem('token')
      if(value===true){
        API.openSystem({},token).then(res=>{
          if(res.data.code==='0'){
            this.$message.success('系统开启成功')
          }
        })
      }
      else{
        API.closeSystem({},token).then(res=>{
          if(res.data.code==='0'){
            this.$message.success('系统关闭成功')
          }
        })
      }
    },
    querySystem(){
      let token = localStorage.getItem('token')
      API.querySystem({},token).then(res=>{
        if(res.data.code==='0'){
          if(res.data.content==='1'){
            this.value=true
          }else{
            this.value=false
          }
        }
      }).catch(error=>{
        console.log(error)
      })
    }
  }
}
</script>

<style>

</style>